package com.zpself.module.算法练习.排序;

import java.util.Arrays;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/2/5 19:21
 * @Modified By
 */
public class 力扣_506_相对名次 {

    public static void main(String[] args) {

        System.out.println(findRelativeRanks(new int[]{1,5,10,6,2,8}));
    }

    public static String[] findRelativeRanks(int[] nums) {
        int length = nums.length;
        String[] result = new String[length];
        int[] array = new int[length];
        System.arraycopy(nums,0,array,0,length);
        //排序
        Arrays.sort(array);
        for (int i = 0; i < nums.length; i++) {
            int rank = length-Arrays.binarySearch(array, nums[i]);
            switch (rank){
                case 1 : result[i]="Gold Medal";
                    break;
                case 2 : result[i]="Silver Medal";
                    break;
                case 3 : result[i]="Bronze Medal";
                    break;
                default:result[i] = String.valueOf(rank);
            }
        }
        return result;
    }
}
